{extend name="public/base"}
{block name="style"}{/block}
{block name="breadcrumb2" title="当前位置"}{/block}
//正文区域
{block name="body"}
<div class="page-container ">
<!--    <div class="text-c">
        <form class="Huiform" method="post" action="" target="_self">
            <input type="text" class="input-text" style="width:250px" placeholder="权限名称" id="" name="">
            <button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜权限节点</button>
        </form>
    </div>-->
    <div class="cl pd-5 bg-1 bk-gray mb-10">
    <span class="l">

    <button onClick="list_add()" class="btn btn-primary radius" type="button">
        <i class="Hui-iconfont">&#xe600;</i> 添加
    </button>

    <button onClick="list_batch_edit()" class="btn btn-secondary radius" type="button">
        <i class="Hui-iconfont">&#xe647;</i> 修改
    </button>

    <button onClick="list_batch_del()" class="btn btn-danger  radius" type="button">
        <i class="Hui-iconfont">&#xe6e2;</i> 删除
    </button>

    <span style=" line-height:30px; color:#CCCCCC; margin-left:10px;">双击可编辑数据</span>

    </span> 
    <span class="l ml-20">
        <form class="Huiform" method="get" action="" >
            <span class="select-box" style="width:150px;">
                            <select class="select valid" size="1" name="searchField">
                                    <option value="0"> --全部-- </option>
{volist name="searchFieldList" id="select_name"}
                            <option value="{$key}" {eq name="key" value="$searchField"}selected{/eq}>{$select_name}</option>
{/volist}

                            </select>
            </span>
            <input type="text" class="input-text" style="width:250px" placeholder="请输入"  name="searchValue" value="{$searchValue | default = "" }">
            <button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> GO </button>
        </form>
    </span>
    
    <span class="r ml-20">
<!--         <button onClick="location.replace(location.href)" class="btn btn-success radius" type="button">
        <i class="Hui-iconfont">&#xe68f;</i> 刷新
        </button> -->
    </span>
    
    </div>
    <form class="Huiform" method="get" action="" id="listForm">
    <table class="table table-border table-bordered table-bg table-tr-hover">
        <thead>
            <tr class="text-c">
                <th width="25">
                    <input type="checkbox" name="" value="">
                </th>
                <th width="100">设备名称</th>
                <th>设备代码</th>
                <th>设备安装地点</th>
                <th >设备类型</th>

                <th>印章数量</th>
                <th>app版本号</th>

                <th width="80">设备状态</th>
                <th width="50">排序</th>
                <th width="100">操作</th>
            </tr>
        </thead>
        <tbody>
{volist name="list|default=[]" id="vo"}
            <tr class="text-c">
                <td><input type="checkbox" value="{$vo.id}" name="id[]" title="{$vo.id}"></td>
                <td>{$vo.equipment_name}</td>
                <td>{$vo.equipment_code}</td>
                <td>{$vo.equipment_address}</td>
                <td>{$vo.equipment_type|opt}</td>
                <td>{$vo.equipment_seal_num}</td>
                <td>{$vo.equipment_app_version}</td>
                <td>{$vo.equipment_status_text}</td>
                <td><input type="text" class="input-text" value="{$vo.sort}" style="text-align:center;"  
                changeeidt="sort_{$vo.id}"
                /></td>

                <td>

                <button onClick="list_edit({$vo.id})" type="button" class="btn btn-secondary size-MINI radius" title=" 编辑">
                    <i class="Hui-iconfont">&#xe6df;</i>
                </button>

                <button onClick="list_del(this,{$vo.id})" type="button" class="btn btn-danger size-MINI radius" title="删除">
                    <i class="Hui-iconfont">&#xe6e2;</i> 
                </button>


                </td>
{/volist}
            </tr>
        </tbody>
    </table>
    </form>
    <div class="pagination-wraper cl">
        {$list->render()}
    </div>
</div>
{/block}
<!--请在下方写此页面业务相关的脚本-->
//-----------------------------------------------------------------------------------------------
{block name="script"}

<script type="text/javascript">


var $listForm = $('#listForm'); // form#listForm
var url_edit ='{:url('edit')}';
var url_del ='{:url('del')}';
var url_change_edit ='{:url('changeeidt')}';
/*添加*/
function list_add(){
    var title= '添加数据';
    var url = url_edit ; 
    layer_show_full(title,url);
}
/*行内 编辑*/
function list_edit(id){
    var title = '修改数据';
    var url = url_edit + '?id=' + id ; 
    layer_show_full(title,url);
}

function list_batch_edit(){
    var id = $listForm.find('[name^=id]:checked ').val();
    if(!id){
        layer.msg('请选择要操作的数据',{icon:1});return;
    }else{
        list_edit(id);
    }
}

/*行内(tr)内点击删除*/
function list_del(obj,id){
    layer.confirm('确认要【删除】吗？',function(index){
        $.ajax({
            type: 'POST',
            url: url_del,
            data:{id:id},
            dataType: 'json',
            success: function(d){
                if(d.code == 1){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});  
                }else{
                    layer.msg(d.msg,{icon:0,time:3000});  
                }

            },
            error:function(d) {
                console.log(d.msg);
            },
        });     
    });
}
/* 批量删除 */
function list_batch_del(){

    if( $("[name^=id]:checked").length == 0  ){
        layer.msg('请选择要操作的数据',{icon:0});return false;
    };
    layer.confirm('确认要【删除】选中数据吗？',function(index){
        $.ajax({
            type: 'POST',
            url:url_del,
            data:$listForm.serialize() ,
            dataType: 'json',
            success: function(d){
                if(d.code == 1){
                    layer.msg('已删除!',{icon:1,time:1000});
                    $("[name^=id]:checked").parents("tr").remove();
                }else{
                    jBox.tip(d.msg,'error');
                }               
            },
            error:function(d) {
                console.log(d.msg);
            },
        });     
    });
}


$(function(){
    //双击修改
    $listForm.find('tbody tr').on('dblclick',function(e){

        console.log( e.target.nodeName );
        if(e.target.nodeName == 'INPUT' ){return false;}
        if(e.target.nodeName == 'BUTTON' ){return false;}
        if(e.target.nodeName == 'A' ){return false;}
        var id = $(this).find('[name^=id]').val();
        list_edit(id);
    });

    //ajax 修改排序 
    $listForm.find('tbody').on('change','[changeeidt]',function(){
        console.log('ajax 修改排序:');
        var data={};
        var a = $(this).attr('changeeidt').split("_");
        data.field = a[0];
        data.id = a[1];
        data.value = $(this).val(); 
        $.ajax({
            type: 'POST',
            url:url_change_edit,
            data:data ,
            dataType: 'json',
            success: function(d){
                if(d.code == 1){
                    layer.msg('更新成功!',{icon:1,time:1000});
                }else{
                    layer.msg('更新失败!',{icon:2,time:1000});
                }               
            },
            error:function(a,b,c) {
                console.log('ajaxerr:',  b, c);
            },
        });     
    });





});//$(function(){



</script>

<style>
	

	
</style>



{/block}{//---------------------------------------------------------------------------}